<?php
require_once '../includes/constants.php';
require_once '../includes/usuario.php';
$usuario = new usuario();
$exito = false;

// <editor-fold defaultstate="collapsed" desc="Registro de Usuario">
if (isset($_POST['enviar'])) {
    $data = $_POST;
    unset($data['password2'], $data['enviar']);
    $data['imagen'] = $_FILES;
    $exito = $usuario->registrar($data);
}
// </editor-fold>
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Registrar usuario</title>
        <link href="../css/style.css" media="all" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="../js/jquery-validate/jquery.validate.min.js"></script>
        <script type="text/javascript" src="../js/jquery-validate/localization/messages_es.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#form1").validate({
                    rules:{
                        foto:{accept:"jpg|png"},
                        nombre:{minlength:3},
                        apellido:{minlength:3},
                        login:{
                            minlength:6, 
                            maxlength:20,
                            remote:"../includes/Json.php?accion=login_duplicado"
                        },
                        password:{minlength:6},
                        password2:{equalTo:"#password"}
                    }
                });
            });
        </script>
    </head>
    <body>
        <div id="header">
            <?php include '../template/header.php'; ?>
        </div>
        <div id="content">
            <?php if (!$exito): ?>
                <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1" enctype="multipart/form-data">
                    <fieldset>
                        <legend>Datos Personales</legend>
                    <table align="center">
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Nombre:</td>
                            <td><input type="text" name="nombre" value="" size="32" class="required" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Apellido:</td>
                            <td><input type="text" name="apellido" value="" size="32" class="required" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Login:</td>
                            <td><input type="text" name="login" value="" size="32" class="required" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Password:</td>
                            <td><input id="password" type="password" name="password" value="" size="32" class="required" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Repita su Password:</td>
                            <td><input type="password" name="password2" value="" size="32" class="required" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Telefono:</td>
                            <td><input type="text" name="telefono" value="" size="32" class="required number" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Telefono2:</td>
                            <td><input type="text" name="telefono2" value="" size="32" class="number" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">email:</td>
                            <td><input type="text" name="email" value="" size="32" class="email required" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Foto:</td>
                            <td><input type="file" name="foto" value="" size="32" /></td>
                        </tr>
                        <tr valign="baseline">
                            <td colspan="2" align="center">
                                <input name="enviar" type="submit" value="Registrar Usuario" />
                            </td>
                        </tr>
                    </table>
                </fieldset>
                </form>
            <?php else: ?>
                <div class="info">
                    <p>Usuario registrado exitosamente, le invitamos a iniciar sesi&oacute;n en la barra superior.</p>
                </div>
            <?php endif; ?>
        </div>
        <div id="footer">
            <?php include '../template/footer.php'; ?>
        </div>
    </body>
</html>